package atri.controller;

import atri.common.Result;
import atri.mapper.BooklistMapper;
import atri.model.Book;
import atri.model.Booklist;
import atri.model.Recommend;
import atri.service.BooklistService;
import jakarta.servlet.http.PushBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class BooklistController {
    @Autowired
    public BooklistService service;
    @Autowired
    public BooklistMapper mapper;

    @GetMapping("/booklist/{re_id}")
    public Result Getlist(@PathVariable int re_id){
        List<Booklist> s = new ArrayList<>();
        s=service.find_re_id(re_id);
        if(s!=null)
        {return  Result.success(s);}
        else
        {return Result.fail();}
    }

    @PostMapping("/booklist")
    public Result save (@RequestBody List<Booklist> booklists){
        int a =service.insert_many(booklists);
        if(a!=0)
        {return Result.success(a);}
        else
        {return Result.fail();}
    }

    @DeleteMapping("/booklist/{id}")
    public Result remove(@PathVariable int id){
        Boolean a = service.del_re_id(id);
        if(a)
        {return Result.success(a);}
        else
        {return Result.fail();}
    }
}
